<?php

/**
 * This is the model class for table "users".
 *
 * The followings are the available columns in table 'users':
 * @property string $id
 * @property string $email
 * @property string $password_hash
 * @property string $temp_password
 * @property string $first_name
 * @property string $last_name
 * @property integer $created_date
 * @property integer $role_id
 * @property integer $application_id
 * @property integer $status
 * @property string $gender
 * @property string $phone
 * @property string $verify_code
 * @property string $address
 * @property string $google_id
 * @property string $facebook_id
 * @property string $birthday
 */
class Users extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'users';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('email, first_name, last_name, role_id, application_id, status', 'required'),
			array('created_date, role_id, application_id, status', 'numerical', 'integerOnly'=>true),
			array('email, first_name, last_name', 'length', 'max'=>50),
			array('password_hash, verify_code', 'length', 'max'=>100),
			array('temp_password', 'length', 'max'=>30),
			array('gender', 'length', 'max'=>6),
			array('phone', 'length', 'max'=>20),
			array('birthday', 'safe'),
			array('address, google_id, facebook_id, photo', 'length', 'max'=>255),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('photo, id, email, password_hash, temp_password, first_name, last_name, created_date, role_id, application_id, status, gender, phone, verify_code, address, google_id, facebook_id, birthday', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'email' => 'Email',
			'password_hash' => 'Password Hash',
			'temp_password' => 'Temp Password',
			'first_name' => 'First Name',
			'last_name' => 'Last Name',
			'created_date' => 'Created Date',
			'role_id' => 'Role',
			'application_id' => 'Application',
			'status' => 'Status',
			'gender' => 'Gender',
			'phone' => 'Phone',
			'verify_code' => 'Verify Code',
			'address' => 'Address',
			'google_id' => 'Google',
			'facebook_id' => 'Facbook',
			'birthday' => 'Birthday',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('password_hash',$this->password_hash,true);
		$criteria->compare('temp_password',$this->temp_password,true);
		$criteria->compare('first_name',$this->first_name,true);
		$criteria->compare('last_name',$this->last_name,true);
		$criteria->compare('created_date',$this->created_date);
		$criteria->compare('role_id',$this->role_id);
		$criteria->compare('application_id',$this->application_id);
		$criteria->compare('status',$this->status);
		$criteria->compare('gender',$this->gender,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('verify_code',$this->verify_code,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('google_id',$this->google_id,true);
		$criteria->compare('facebook_id',$this->facebook_id,true);
		$criteria->compare('birthday',$this->birthday,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Users the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
